package demo;

import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SeqUtil {

    @Test
    public void test() {
        List<String> strings = getPath("E:\\temp\\test3");
        for (String string : strings) {
            System.out.println(string);
        }

    }
    public List<String>  getPath(String localPath){
        List<String> paths = new ArrayList<>();
        getRealPath(localPath,paths);
        cutPath(localPath,paths);
        return paths;
    }

    //    得到的目录应该是基于选中的文件的，不能是相对磁盘的路径，
    public void getRealPath(String path,List<String> paths) {
        File file = new File(path);
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isDirectory()){
                getRealPath(file1.toString(),paths);
                continue;
            }
            paths.add(file1.toString());
        }


    }

//    剪切路径

    /**
     *
     * @param localPath 大文件的路径
     * @param smallLocalPaths 小文件的本地路径集
     * @return
     */
    public List<String> cutPath(String localPath,List<String> smallLocalPaths){
        String[] split = localPath.split("\\\\");
        int length = split[split.length - 1].length();
        int cutLen=localPath.length()- length;
        for (int i = 0; i < smallLocalPaths.size(); i++) {
            smallLocalPaths.set(i,smallLocalPaths.get(i).substring(cutLen));
        }
        return smallLocalPaths;
    }
}
